package routers

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
	"go-learn/src/beego-learn/controllers"
)

func init() {
	beego.Router("/", &controllers.MainController{})

	beego.Router("/main/test", &controllers.MainController{},"*:Test")

	//指定访问方式:方法名
	beego.Router("/main/test1",&controllers.MainController{},"get,post:Test")

	//同一路由根据get/post方式区分不同访问方法
	beego.Router("/main/simple",&controllers.MainController{},"get:GetFunc;post:PostFunc")

	//基本GET路由
	beego.Get("/get", func(context *context.Context) {
		context.Output.Body([]byte("hello world"))
	})

	//基本POST路由
	beego.Post("post", func(i *context.Context) {
		i.Output.Body([]byte("hello beego"))
	})

	//支持所有请求方法
	beego.Any("/foo", func(i *context.Context) {
		i.Output.Body([]byte("test"))
	})

	//自动路由，真的傻，http://127.0.0.1:8080/main/postfunc(访问maincontroller的)
	beego.AutoRouter(&controllers.MainController{})

	//正则路由:127.0.0.1:8080/api/123
	beego.Router("/api/?:id",&controllers.MainController{},"get:RegApi")

}
